/**
 * 对象关系映射（ORM）用于测试连接数据库处理
 */
const Sequelize = require('sequelize');
// new Sequelize("表名","用户名","密码",配置)
const sequelize = new Sequelize(process.env.database, process.env.username, process.env.password, {
  host: process.env.host, // 主机号
  dialect: 'mysql', // 连接的数据库类型
  timezone: '+08:00',
  logging: false // 禁用数据库操作日志
});

sequelize
  .authenticate() // 测试链接
  .then(function () {
    console.log('Database connection has been established successfully. 数据库连接成功'); // 成功连接
  })
  .catch(function (err) {
    console.log('Unable to connect to the database:', err); // 连接失败
  });

module.exports = sequelize;
